import time
import io

import sys
from appium import webdriver

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf8')

desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['platformVersion'] = '7.1'
desired_caps['deviceName'] = '192.168.176.102:5555'
desired_caps['appPackage'] = 'com.android.settings'
desired_caps['appActivity'] = '.Settings'
desired_caps['unicodeKeyboard'] = True
desired_caps['resetKeyboard'] = True
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)

# # 点击搜索框
# driver.find_element_by_id('com.android.settings:id/search').click()
# time.sleep(3)
# # 输入‘hello’
# driver.find_element_by_class_name('android.widget.EditText').send_keys('你好')
# time.sleep(3)
# driver.find_element_by_class_name('android.widget.EditText').clear()

# eles = driver.find_elements_by_class_name('android.widget.TextView')
# for i in eles:
#     text = i.get_attribute('name')
#     print(text)
# print('*'*50)
# for i in eles:
#     print(i.get_attribute("text"))
# print('*'*50)
# for i in eles:
#     print(i.get_attribute("className"))
# print('*'*50)
# for i in eles:
#     print(i.get_attribute("resourceId"))
# print('*'*50)

print(driver.find_element_by_id('com.android.settings:id/search').location)